//
//  shipgdsDetailViewController.m
//  WHB_logist
//
//  Created by 徐国庆 on 15/12/5.
//  Copyright (c) 2015年 turing. All rights reserved.
//

#import "shipgdsDetailViewController.h"

@interface shipgdsDetailViewController ()<UITableViewDataSource, UITableViewDelegate>

@property(nonatomic, strong)UITableView *tableView;
@property(nonatomic, strong)goodsList   *goods;

@end

@implementation shipgdsDetailViewController

- (instancetype)initWithGoodsList:(goodsList *)goods{
    self = [super init];
    if (self) {
        self.goods = goods;
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.navtitle.text = @"货源详情";
    [self initWithView];
    
}

#pragma mark UITableViewDelegate
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 3;
}



- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *indentifer = @"shipgdsDetailCell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:indentifer];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:indentifer];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    if (indexPath.row == 0) {
        
        // “上线”
        UILabel *topLine = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, kUIScreenWidth, 0.5)];
        topLine.backgroundColor = [UIColor HexStrWithColor:@"d0d0d0"];
        [cell.contentView addSubview:topLine];
        
        // "发布时间"
        UIView *publishView = [self titleAndContent:@"发布时间:" andContent:self.goods.loadGoodsTime withToAddress:nil];
        publishView.frame = CGRectMake(0, 1, kUIScreenHeight, 30);
        [cell.contentView addSubview:publishView];
        
        // 发布时间下的“线”
        UILabel *bottomLine = [[UILabel alloc] initWithFrame:CGRectMake(0, 35, kUIScreenWidth, 0.5)];
        bottomLine.backgroundColor = [UIColor HexStrWithColor:@"d0d0d0"];
        [cell.contentView addSubview:bottomLine];
        
        // “发布企业”
        UIView *businessView = [self titleAndContent:@"发布企业:" andContent:self.goods.releaseOrgName withToAddress:nil];
        businessView.frame = CGRectMake(0, publishView.frame.origin.y + publishView.frame.size.height, kUIScreenHeight, 30);
        [cell.contentView addSubview:businessView];
        
        // “取货日期”
        UIView *receiveGoodsView = [self titleAndContent:@"取货日期:" andContent:@"2015-08-12" withToAddress:nil];
        receiveGoodsView.frame = CGRectMake(0, businessView.frame.origin.y + businessView.frame.size.height, kUIScreenHeight, 30);
        [cell.contentView addSubview:receiveGoodsView];
        
        // "路线"
        UIView *addressView = [self titleAndContent:@"路线:" andContent:self.goods.startAddressName withToAddress:self.goods.endAddressName];
        addressView.frame = CGRectMake(0, receiveGoodsView.frame.origin.y + receiveGoodsView.frame.size.height, kUIScreenHeight, 30);
        [cell.contentView addSubview:addressView];
        
        // “运输介质”
        UIView *mediumView = [self titleAndContent:@"运输介质:" andContent:self.goods.mediumType withToAddress:nil];
        mediumView.frame = CGRectMake(0, addressView.frame.origin.y + addressView.frame.size.height, kUIScreenHeight, 30);
        [cell.contentView addSubview:mediumView];
        
        // “重量”
        UIView *weightView = [self titleAndContent:@"重量:" andContent:self.goods.weight withToAddress:nil];
        weightView.frame = CGRectMake(0, mediumView.frame.origin.y + mediumView.frame.size.height, kUIScreenHeight, 30);
        [cell.contentView addSubview:weightView];
        
        // “价格区间”
        UIView *priceView = [self titleAndContent:@"价格区间:" andContent:self.goods.expectFreight withToAddress:nil];
        priceView.frame = CGRectMake(0, weightView.frame.origin.y + weightView.frame.size.height, kUIScreenHeight, 30);
        [cell.contentView addSubview:priceView];
        
        // “备注”
        UIView *remarkView = [self titleAndContent:@"备注:" andContent:self.goods.note withToAddress:nil];
        remarkView.frame = CGRectMake(0, priceView.frame.origin.y + priceView.frame.size.height, kUIScreenHeight, 30);
        [cell.contentView addSubview:remarkView];
        
        // 备注下面的“空白”条
        UILabel *stripLabel = [[UILabel alloc] initWithFrame:CGRectMake(-1, remarkView.frame.origin.y + remarkView.frame.size.height + 10, kUIScreenWidth + 2, 10)];
        stripLabel.backgroundColor = [UIColor HexStrWithColor:@"FCFCFC"];
        stripLabel.layer.masksToBounds = YES;
        stripLabel.layer.borderWidth = 0.5;
        stripLabel.layer.borderColor = [UIColor HexStrWithColor:@"ADADAD"].CGColor;
        [cell.contentView addSubview:stripLabel];

    } else if (indexPath.row == 1){
        // "取货方"
        UIView *publishView = [self titleAndContent:@"取货方:" andContent:@"中广核集团" withToAddress:nil];
        publishView.frame = CGRectMake(0, 1, kUIScreenHeight, 30);
        [cell.contentView addSubview:publishView];
        
        // “取货地址”
        UIView *businessView = [self titleAndContent:@"取货地址:" andContent:@"哈尔滨南岗区西大直街318号6楼哈尔滨南岗区西大直街318号6楼" withToAddress:nil];
        businessView.frame = CGRectMake(0, publishView.frame.origin.y + publishView.frame.size.height, kUIScreenHeight, 30);
        [cell.contentView addSubview:businessView];
        
        // “取货电话”
        UIView *receiveGoodsView = [self titleAndContent:@"取货电话:" andContent:@"15011223366" withToAddress:nil];
        receiveGoodsView.frame = CGRectMake(0, businessView.frame.origin.y + businessView.frame.size.height, kUIScreenHeight, 30);
        [cell.contentView addSubview:receiveGoodsView];
        
        // 取货电话下面的“空白”条
        UILabel *stripLabel = [[UILabel alloc] initWithFrame:CGRectMake(-1, receiveGoodsView.frame.origin.y + receiveGoodsView.frame.size.height + 10, kUIScreenWidth + 2, 10)];
        stripLabel.backgroundColor = [UIColor HexStrWithColor:@"FCFCFC"];
        stripLabel.layer.masksToBounds = YES;
        stripLabel.layer.borderWidth = 0.5;
        stripLabel.layer.borderColor = [UIColor HexStrWithColor:@"ADADAD"].CGColor;
        [cell.contentView addSubview:stripLabel];

    } else if (indexPath.row == 2){
        // "收货方"
        UIView *publishView = [self titleAndContent:@"收货方:" andContent:@"ABC集团" withToAddress:nil];
        publishView.frame = CGRectMake(0, 1, kUIScreenHeight, 30);
        [cell.contentView addSubview:publishView];
        
        // “收货地址”
        UIView *businessView = [self titleAndContent:@"收货地址:" andContent:@"哈尔滨南岗区西大直街318号6楼哈尔滨南岗区西大直街318号6楼" withToAddress:nil];
        businessView.frame = CGRectMake(0, publishView.frame.origin.y + publishView.frame.size.height, kUIScreenHeight, 30);
        [cell.contentView addSubview:businessView];
        
        // “收货电话”
        UIView *receiveGoodsView = [self titleAndContent:@"收货电话:" andContent:@"15011223366" withToAddress:nil];
        receiveGoodsView.frame = CGRectMake(0, businessView.frame.origin.y + businessView.frame.size.height, kUIScreenHeight, 30);
        [cell.contentView addSubview:receiveGoodsView];

    }
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row == 0) {
        return 260;
    } else if (indexPath.row == 1 || indexPath.row == 2){
        return 110;
    }
    return 260;
}

- (void)initWithView{
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, kUIScreenWidth, kUIScreenHeight - kNavHeight) style:UITableViewStylePlain];
    self.tableView.dataSource = self;
    self.tableView.delegate = self;
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.view addSubview:self.tableView];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
